package com.h3c.gm.service

import com.google.common.collect.Lists
import com.google.common.collect.Maps
import com.h3c.gm.common.utils.ListUtils
import com.h3c.gm.dao.IBusOrgDao
import com.h3c.gm.entity.DO.BusOrgDO
import com.h3c.gm.entity.VO.BusOrgVO
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service

import javax.annotation.Resource

/**
 * Created by d14287 on 2017/6/26.
 */
@Service
class BusOrgService {
    @Resource
    IBusOrgDao busOrgDao

    int getCount() {
        busOrgDao.getCount(Maps.newHashMap())
    }

    int getProCount(String province) {
        def queryParams = Maps.newHashMap()
        queryParams.put('province', province)
        busOrgDao.getCount(queryParams)
    }

    List<BusOrgVO> getOrgs() {
        def busOrgDOList = busOrgDao.getOrgs(Maps.newHashMap())
        def busOrgVOList = Lists.newArrayList()
        busOrgDOList.each {
            item ->
                def busOrgVO = new BusOrgVO()
                busOrgVO.copyFromDO(item)
                busOrgVOList.add(busOrgVO)
        }
        return busOrgVOList
    }

    BusOrgVO getOrg(String orgkey) {
        def busOrgDO = busOrgDao.getOrgByOrgkey(orgkey)
        def busOrgVO = new BusOrgVO()
        BeanUtils.copyProperties(busOrgDO, busOrgVO)
        return busOrgVO
    }

    List<BusOrgVO> getProOrgs(String province) {
        def queryParams = Maps.newHashMap()
        queryParams.put('province', province)
        def busOrgDOList = busOrgDao.getOrgs(queryParams)
        def busOrgVOList = Lists.newArrayList()
        busOrgDOList.each {
            item ->
                def busOrgVO = new BusOrgVO()
                busOrgVO.copyFromDO(item)
                busOrgVOList.add(busOrgVO)
        }
        return busOrgVOList
    }

    List<Map<String, Integer>> getCityOrgs() {
        busOrgDao.getCityOrgs()
    }

    Map<String, Object> getCityOrg(String city) {
        def busOrgsList = busOrgDao.getCityOrg(city)
        def map = Maps.newHashMap()
        map.put('city', city)
        map.put('conut', busOrgsList.size())
        map.put('list', busOrgsList)
        return map
    }

    List<BusOrgVO> getOrgByCity(String city) {
        busOrgDao.getCityOrg(city)
    }

    List<String> getOrgkeyList(String province) {
        def busOrgDOs = busOrgDao.getCityOrg(province)
        def orgkeys = Lists.newArrayList()
        busOrgDOs.each {
            item ->
                orgkeys.add(item.getOrgkey())
        }
        return orgkeys
    }
}
